<?php
namespace app\admin\controller;
use framework\ext\Check;

class WebsiteController extends \app\base\controller\AdminController{

    //列表
    public function index(){
        $act = form('get.act');
        if($act == 'del'){
            $condition['id'] = form('get.id',0,intval);
            $result =  model('website')->_delete($condition);
            if($result){
                $this->jsonMsg('删除成功',1);
            }else{
                $this->jsonMsg('删除失败');
            }
        }else{
            $this->list = model('website')->_select();
            $this->display();
        }
    }

    //添加
    public function add(){
       if($this->isPost()){
            $msg = Check::rule(
                array(check::must($_POST['name']),'站点名称必须选择'),
                array(check::must($_POST['tpl_index']),'首页模版必须填写'));
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            $data = array();
            $data = form('post');
            $data['uptime'] = time();
            $result =  model('website')->_update($data);
            if($result){
                $this->jsonMsg('站点添加成功',1,url('website/index'));
            }else{
                $this->jsonMsg('站点添加失败');
            }
        }else{
            $this->display();
        }   
    }

    //编辑
    public function edit(){
        if($this->isPost()){
            $data = form('post',array('fid'));
            $data['uptime'] = time();
            $condition['id'] = form('post.fid',0,intval);
            $result =  model('website')->_update($data,$condition);
            if($result){
                $this->jsonMsg('站点编辑成功',1,url('website/index')); 
            }else{
                $this->jsonMsg('站点编辑失败');
            }
        }else{
            $this->fid = form('get.id',0,intval);
            $condition['id'] = $this->fid;
            $this->info = model('website')->_find($condition);
            $this->display();   
        }
    }
}